package com.luoying.itew.util;

import com.luoying.itew.bean.UserInfo;
import com.luoying.itew.common.Constant;
import com.luoying.itew.manage.UserManage;

public class StateContext {

    private IState iState;
    /**
     * 红色预警启用状态
     */
    private boolean enableState ;
    private int warnStatus;

    /**
     *
     * @param enable 是否开启预警
     * @param warn 预警状态
     */
    public StateContext(int enable, int warn){
        warnStatus = warn;
        if(enableState = enable == 1){
            iState = new StateRed();
            return;
        }
        UserInfo userInfo = UserManage.getInstance().getUserInfo();
        if(userInfo==null) {
            iState = new StateGreen();
        }
        if(userInfo.getUserType()==0)
            iState = new managerFactory().factory(warnStatus);
        else
            iState = new govFactory().factory(warnStatus);
    }

    public int stateLeve(){
        return iState.stateLevel();
    }

    public int levelColor(){
        return iState.levelColor();
    }

    public String levelStr(){
        return iState.levelStr();
    }


    /**
     * 安泰用户管理类
     */
    static class managerFactory {
        IState factory(int status){
            IState target;
            switch (status){
                case Constant.MONITOR_WARN_COEFFICIENT_GREEN:
                default:
                    target = new StateGreen();
                    break;
                case Constant.MONITOR_WARN_COEFFICIENT_YELLOW:
                    target = new StateYellow();
                    break;
                case Constant.MONITOR_WARN_COEFFICIENT_ORANGE:
                    target = new StateOrange();
                    break;
                case Constant.MONITOR_WARN_COEFFICIENT_RED:
                    target = new StateRed();
                    break;
            }
            return target;
        }
    }

    /**
     *
     */
    static class govFactory {
        IState factory(int status){
            IState target;
            switch (status){
                case Constant.MONITOR_WARN_COEFFICIENT_GREEN:
                default:
                    target = new StateGreen();
                    break;
                case Constant.MONITOR_WARN_COEFFICIENT_YELLOW:
                case Constant.MONITOR_WARN_COEFFICIENT_ORANGE:
                case Constant.MONITOR_WARN_COEFFICIENT_RED:
                    target = new StateYellow();
                    break;
            }
            return target;
        }
    }
}
